Partial Public Class CreateNewAccount
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            ddlTimeZone.DataSource = TimeZoneList.GetTimeZoneList
            ddlTimeZone.DataBind()
            rptEmailNotification.DataSource = getNotificationOptions()
            rptEmailNotification.DataBind()
        End If
    End Sub


    Private Sub btnCreateAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreateAccount.Click
        Dim hMACIString As String
        Try
            Dim c As HttpCookie = Request.Cookies("hMACIString")
            hMACIString = c.Value
        Catch
        End Try
        Dim b As KDESolutions.Utilities.RandomStringGenerator
        If (hMACIString = b.HashMACMe(txtConfirmImage.Text)) Then
            validateImage.IsValid = True
        Else
            validateImage.IsValid = False
        End If
        If validateImage.IsValid = True Then
            Dim newStatus As New MembershipCreateStatus
            System.Web.Security.Membership.CreateUser(txtUserName.Text, Password.Text, txtEmail.Text, txtSecurityQuestion.Text, txtSecurityAnswer.Text, False, newStatus)
            Select Case newStatus
                Case MembershipCreateStatus.DuplicateEmail
                    validateCreate.ErrorMessage = "You have entered an email address that has already been registered."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.DuplicateUserName
                    validateCreate.ErrorMessage = "The username you have selected has already been registered."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.InvalidQuestion
                    validateCreate.ErrorMessage = "Your security question is inavlid."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.InvalidAnswer
                    validateCreate.ErrorMessage = "The answer to your security question is invalid."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.InvalidEmail
                    validateCreate.ErrorMessage = "You have entered an invalid email address."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.InvalidUserName
                    validateCreate.ErrorMessage = "You have entered an invalid username."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.ProviderError
                    validateCreate.ErrorMessage = "An error occurred trying to create your account, please contact the system administrator."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.UserRejected
                    validateCreate.ErrorMessage = "Your request to create an account has been rejected, please contact the system administrator."
                    validateCreate.IsValid = False
                Case MembershipCreateStatus.Success
                    Response.Redirect("~/Default.aspx")
            End Select
        End If
    End Sub

    Private Function getNotificationOptions() As Hashtable
        Dim returnHashTable As New Hashtable
        returnHashTable.Add("Admin", "Email from Administrators")
        returnHashTable.Add("News", "Newsletters")
        returnHashTable.Add("Events", "Upcoming Events")
        return returnHashTable
    End Function
End Class